package IOStreamTest.DataStream;

import java.io.DataOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/*
DataOutputStream:数据专属的流
    这个流可以将数据连同数据类型一并写入文件
    注意:这个文件不是普通文本文档(使用文本编辑器打不开)
 */
public class DataOutputStreamTest1 {
    public static void main(String[] args) {
        DataOutputStream dos = null;
        try {
            dos = new DataOutputStream(new FileOutputStream("D:\\data"));
            int i = 100;
            byte b = 97;
            short s = 123;
            long l = 100l;
            float f = 100F;
            double d = 123.2;
            boolean bo = true;
            char c = '我';
            dos.writeInt(i);
            dos.writeShort(s);
            dos.writeByte(b);
            dos.writeLong(l);
            dos.writeFloat(f);
            dos.writeDouble(d);
            dos.writeBoolean(bo);
            dos.writeChar(c);
            dos.flush();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally{
            if (dos != null) {
                try {
                    dos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
